package wsserver

// IActionEvent 定义单个action操作时间
type IActionEvent interface {
	Name() string
	Do(client *Client, data []byte)
}

type ActionEvent struct {
	name  string
	event func(*Client, []byte)
}

func NewActionEvent(name string, f func(client *Client, data []byte)) *ActionEvent {
	return &ActionEvent{
		name:  name,
		event: f,
	}
}

func (act *ActionEvent) Name() string {
	return act.name
}

func (act *ActionEvent) Do(client *Client, data []byte) {
	if act.event == nil {
		return
	}
	act.event(client, data)
}
